package com.hqyj.springBoot.modules.test.dao;

import com.hqyj.springBoot.modules.test.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface StudentDao extends JpaRepository<Student,Integer> {
    //findBy + 属性 + 关键字 + 属性(option);
    //find + Top || First(option) + By + 属性 + 关键字 + 属性(option);
    Student findFirstByName(String name);

//    @Query(nativeQuery = true,value = "select * from test_student where id = :id")//:加@Param的参数进行占位
    @Query(value = "from Student where id = :id")//HQL
    Student getStudentById(@Param("id") int id);

    @Modifying
    @Query(nativeQuery = true,value = "update test_student set name = :#{#student.name}," +
            "age = :#{#student.age} where id = :#{#student.id}" )//注意占位
    void updateStudent(@Param("student") Student student);
}
